package design_7_bridge.demo1.bridge.impl;

import design_7_bridge.demo1.bridge.MsgServiceBridge;
import design_7_bridge.demo1.service.MsgService;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 异步消息 / 延时消息, 直接调用
 *
 * @author wangsong
 * @email 1720696548@qq.com
 * @date 2022/4/14 11:42
 */
public class AsynMsg extends MsgServiceBridge {


	public AsynMsg(String msgData, MsgService msgService) {
		super(msgData, msgService);
	}

	@Override
	public void sendMsg() {

		ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(5);
		System.out.println("收到延时消息：10秒后在进行发送");
		newScheduledThreadPool.schedule(new Runnable() {
			@Override
			public void run() {
				msgService.sendMsg(msgData);
			}
			// 10秒后执行
		}, 10, TimeUnit.SECONDS);
	}

}